import JT
import time
import numpy
from enthought.mayavi.mlab import *
import cPickle

fixedImageName = 'C:/Users/bryan/bryan-code/2D3D/vert1/fluoro/ushortim080-LAT.mhd'
movingImageName = 'C:/Users/bryan/bryan-code/trunk/Images/CalibratedDRRImage.mhd'
outFileName = 'C:/Users/bryan/bryan-code/trunk/Images/RegOut.png'
outPath = 'C:/Users/bryan/bryan-code/trunk/Images/DRR/'
baseName = 'DRR_'

reg=JT.NewRegistration()
reg.SetImageMetric('NC')

print "Current Metric: ", reg._metricName
nDim = 11.0
startPos = -nDim+1
out = numpy.zeros((nDim,nDim))

for i in range(nDim):
    for j in range(nDim):
        imgSeqPath = outPath+baseName+'_x%sy%s.png' % (str(int(startPos+i*2)),str(int(startPos+j*2)))
        #imgSeqPath = outPath+baseName+'%s.png' % str(i)
        start=time.clock()
        reg.SetFixedFileName(fixedImageName)
        reg.SetMovingFileName(imgSeqPath)
        val = reg.GetMetric()
        end=time.clock()
        out[i][j] = val
        print "[%.0f%%] Metric Value: %f, Time (s): %f" % (((i*nDim)+j)/(nDim**2)*100,val,end-start)

path = outPath+'metricArray.out'
f=open(path,'w')
cPickle.dump(out,f)
f.close()
print "output pickled to: ", path
surf(out)